Event Object |
|
An event object carries information that an event listener requires to perform a certain activity. When an event listener is called, an event object (instance of interface BsfEvent) is passed as a part of the transaction. An event object contains the following:
- The BusObject on which the event is fired. All event objects that pass a BusObject implement theBusObjectEventinterface
- Name of the attribute (for attribute-level event listeners)
- The event trigger that causes the event
Example
To understand the behavior of an event object, consider a scenario where an AfterCommitObject event listener is invoked, and an AfterCommitObjectEvent is passed. Using the method event.triggeredBy() on the event, you can determine the operation that was performed on the object. If an object has been updated during the transaction, applying the method getOriginalObject on the event returns the object with its original state (the state of the object before the transaction started). The following code explains this:
public void onAfterCommit(AfterCommitObjectEvent event) { // was the operation an update? If ( event.triggeredBy(StdTriggers.UPDATE_OBJECT) ) { // get the state of the object before the transaction BusObject oldObject = event.getOriginalObject(); // get the current object BusObject curObject = event.getObject(); // perform additional logic on both objects } }
Thus, event objects help in retrieving the state of an object at any stage of a transaction.